home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Papers / Downs.FileSystem / source / notification / AERoutines.c next >
Encoding:
C/C++ Source or Header  |  1999-06-24  |  2.9 KB  |  138 lines  |  [TEXT/CWIE]

  1. /**************************
  2.     AERoutines.c
  3. **************************/
  4.  
  5. #include "extern.h"
  6. #include "AppleEvents.h"
  7. #include "Balloons.h"
  8. #include "Folders.h"
  9. #include "GestaltEqu.h"
  10. #include "Packages.h"
  11. #include "Traps.h"
  12.  
  13.  
  14. void        DoAEInstallation( void );
  15. pascal        OSErr HandleCreate( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon );
  16. void        DoHandleAERequest( FSSpec theSpec );
  17. OSErr        DoRequiredCheck( AppleEvent *theAppleEvent );
  18.  
  19. const    OSType        kTestEventClass = 'asd9';
  20. const    OSType        kCreateEventId = 'newf';
  21.  
  22.  
  23. /**************************
  24.     DoAEInstallation
  25. **************************/
  26.  
  27. void DoAEInstallation( void )
  28. {
  29.     AEInstallEventHandler( kTestEventClass, kCreateEventId,
  30.                         (AEEventHandlerProcPtr)HandleCreate, 0, false );
  31. }
  32.  
  33.  
  34. /**************************
  35.     HandleCreate
  36. **************************/
  37.  
  38. pascal OSErr HandleCreate( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon )
  39. {
  40.     long                i, itemsInList;
  41.     short                theFileRefNum, theCount;
  42.     AEDescList            docList;
  43.     AEKeyword            theKeyword;
  44.     DescType            typeCode;
  45.     FInfo                theFInfo;
  46.     FSSpec                theFSS;
  47.      OSErr                theErr;
  48.     SFTypeList            theTypeList;
  49.     Size                actualSize;
  50.  
  51.      theErr = AEGetParamDesc( theAppleEvent, keyDirectObject, typeAEList, &docList );
  52.     if ( theErr )
  53.         return ( theErr );
  54.  
  55.      theErr = DoRequiredCheck( theAppleEvent );
  56.     if ( theErr )
  57.         return ( theErr );
  58.  
  59.      theErr = AECountItems( &docList, &itemsInList );
  60.     if ( theErr )
  61.         return ( theErr );
  62.  
  63.     for ( i = 1; i <= itemsInList; i++ )
  64.     {
  65.          theErr = AEGetNthPtr( &docList, i, typeFSS, &theKeyword, &typeCode, ( Ptr )&theFSS, sizeof( FSSpec ), &actualSize );
  66.         if ( theErr )
  67.             return ( theErr );
  68.  
  69.         FSpGetFInfo( &theFSS, &theFInfo );    
  70.         DoHandleAERequest( theFSS );
  71.     }
  72.  
  73.      return ( errAEEventNotHandled );
  74. }
  75.  
  76.  
  77. /**************************
  78.     DoHandleAERequest
  79. **************************/
  80.  
  81. void    DoHandleAERequest( FSSpec theSpec )
  82. {
  83.     short        theCount, i, j;
  84.     short        tempVRefNum;
  85.     long        tempParID;
  86.     FInfo        theFInfo;
  87.      OSErr        theErr;
  88.     OSType        tempFileType;
  89.     StringPtr    tempStringPtr;
  90.  
  91.     tempStringPtr = ( StringPtr )NewPtrClear( STRING_LENGTH + 1 );
  92.  
  93.     if ( tempStringPtr == NIL )
  94.         return;
  95.         
  96.     //    Save the values.
  97.     tempVRefNum = theSpec.vRefNum;
  98.     tempParID = theSpec.parID;
  99.  
  100.     for ( theCount = 0; theCount <= theSpec.name[ 0 ]; theCount++ )
  101.         tempStringPtr[ theCount ] = theSpec.name[ theCount ];
  102.  
  103.     FSpGetFInfo( &theSpec, &theFInfo );
  104.  
  105.     tempFileType = theFInfo.fdType;
  106.  
  107.     // Do something with incoming data...
  108.  
  109.     DisposPtr( ( Ptr )tempStringPtr );
  110.  
  111.     gRequestPending = false;
  112. }
  113.  
  114.  
  115. /**************************
  116.     DoRequiredCheck
  117. **************************/
  118.  
  119. OSErr        DoRequiredCheck( AppleEvent *theAppleEvent )
  120. {
  121.     OSErr        theErr;
  122.     DescType    typeCode;
  123.     Size        actualSize;
  124.     
  125.     theErr = AEGetAttributePtr( theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  126.                     &typeCode, NIL, NIL, &actualSize );
  127.  
  128.     if ( theErr == errAEDescNotFound )
  129.         return ( noErr );
  130.  
  131.     if ( theErr == noErr )
  132.         return ( errAEEventNotHandled );
  133.  
  134.     return ( theErr );
  135. }
  136.  
  137.  
  138.